find_package(Doxygen)

if (NOT DOXYGEN_FOUND)
	return()
endif()

# Just input XML since this is what breathe consumes
set(DOXYGEN_GENERATE_HTML YES) # no html
set(DOXYGEN_GENERATE_XML YES) # with xml

# Don't generate documentation from implemetaion details
set(DOXYGEN_EXCLUDE_PATTERNS "*/detail/*")

# Print paths relative to include directory
set(DOXYGEN_STRIP_FROM_PATH ${PROJECT_SOURCE_DIR}/include)

# NOTE: use doxygen_add_docs(doxygen-doc ALL ...) if you want your documentaiton 
# to be created by default each time you build. Without the keyword you need to
# explicitly invoke building of the 'doc' target
doxygen_add_docs(doxygen-doc ${PROJECT_SOURCE_DIR}/include COMMENT
	"Generating API documentation with doxygen")

find_package(Sphinx REQUIRED)

configure_file(${CMAKE_CURRENT_SOURCE_DIR}/conf.py.in
	    ${CMAKE_CURRENT_BINARY_DIR}/conf.py @ONLY)

add_custom_target(sphinx-doc ALL
	COMMAND ${SPHINX_EXECUTABLE} -b html -c ${CMAKE_CURRENT_BINARY_DIR}
		${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR}
	WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
	COMMENT "Generating API documentation with sphinx"
	VERBATIM)

add_dependencies(sphinx-doc doxygen-doc)
